package com.ytt.core.util.filter;

/**
 * RemoteAddressUtil
 * 保存和获取HttpServletRequest的真实IP的工具类
 * @author chenwen
 * @date 2019/9/12 16:33
 */
public class RemoteAddressUtil {
    private static final ThreadLocal<String> REMOTE_ADDRESS = new ThreadLocal<>();

    private static final RemoteAddressUtil REMOTE_ADDRESS_UTIL = new RemoteAddressUtil();

    private RemoteAddressUtil() {
    }

    public static RemoteAddressUtil getInstance() {
        return REMOTE_ADDRESS_UTIL;
    }

    public String getAddress() {
        return REMOTE_ADDRESS.get();
    }

    public void setAddress(String address) {
        REMOTE_ADDRESS.remove();
        REMOTE_ADDRESS.set(address);
    }

    public void removeAddress() {
        REMOTE_ADDRESS.remove();
    }
}
